package com.app;

import javax.swing.JTable;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;

public class SelectionListener implements ListSelectionListener {
	JTable table;
	
	SelectionListener(JTable table) {
        this.table = table;
    }
	
	@Override
	public void valueChanged(ListSelectionEvent e) {
		// If cell selection is enabled, both row and column change events are fired
        if (e.getSource() == table.getSelectionModel()
              && table.getRowSelectionAllowed()) {
            // Column selection changed
            int first = e.getFirstIndex();
            int last = e.getLastIndex();
            System.out.println(first+","+last);
        } else if (e.getSource() == table.getColumnModel().getSelectionModel()
               && table.getColumnSelectionAllowed() ){
            // Row selection changed
            int first = e.getFirstIndex();
            int last = e.getLastIndex();
//            System.out.println(first+","+last);
        }

        if (e.getValueIsAdjusting()) {
            // The mouse button has not yet been released
        }

	}

}
